package utils;

import android.content.Context;
import android.os.IBinder;
import android.view.inputmethod.InputMethodManager;

import common.MyApplication;

/**
 * Created by Administrator on 2017/3/13.
 *
 */

public class KeyBoard {
    public static void showKeyBoard() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(400);
                    InputMethodManager imm = (InputMethodManager) MyApplication.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public static void hideKeyBoard(final IBinder windowToken) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) MyApplication.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }).start();
    }
}
